/// 实名认证响应模型
/// 
/// 对应接口: POST /api/user/realname-auth
/// 封装实名认证的响应数据
class RealnameAuthResp {
  /// 是否成功
  final bool success;
  
  /// 状态消息
  final String message;
  
  /// 是否已认证
  final bool? verified;
  
  /// 认证状态（0=未认证，1=审核中，2=已认证）
  final int? authStatus;
  
  /// 真实姓名
  final String? name;
  
  /// 脱敏后的身份证号
  final String? idCardNo;
  
  /// 认证时间
  final String? authTime;

  RealnameAuthResp({
    required this.success,
    required this.message,
    this.verified,
    this.authStatus,
    this.name,
    this.idCardNo,
    this.authTime,
  });

  /// 从JSON创建实名认证响应
  factory RealnameAuthResp.fromJson(Map<String, dynamic> json) {
    final data = json['data'] as Map<String, dynamic>?;
    
    return RealnameAuthResp(
      success: json['status'] == 'success',
      message: json['message']?.toString() ?? '',
      verified: data?['verified'] as bool?,
      authStatus: data?['authStatus'] as int?,
      name: data?['name']?.toString(),
      idCardNo: data?['idCardNo']?.toString(),
      authTime: data?['authTime']?.toString(),
    );
  }

  /// 转换为JSON（用于本地存储）
  Map<String, dynamic> toJson() {
    return {
      'success': success,
      'message': message,
      'verified': verified,
      'authStatus': authStatus,
      'name': name,
      'idCardNo': idCardNo,
      'authTime': authTime,
    };
  }

  /// 成功响应
  factory RealnameAuthResp.success({
    required String message,
    bool? verified,
    int? authStatus,
    String? name,
    String? idCardNo,
    String? authTime,
  }) {
    return RealnameAuthResp(
      success: true,
      message: message,
      verified: verified,
      authStatus: authStatus,
      name: name,
      idCardNo: idCardNo,
      authTime: authTime,
    );
  }

  /// 失败响应
  factory RealnameAuthResp.failure(String message) {
    return RealnameAuthResp(
      success: false,
      message: message,
    );
  }

  @override
  String toString() {
    return 'RealnameAuthResp(success: $success, message: $message, verified: $verified)';
  }
}

